﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Data;
using Hangjing.DBUtility;
using Hangjing.Model;

namespace Hangjing.SQLServerDAL
{

    /// <summary>
    /// 微信退款记录
    /// </summary>
    public partial class WeChat_RefundLog
    {

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(WeChat_RefundLogInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into WeChat_RefundLog(");
            strSql.Append("payorderid,refund_fee,refund_recv_accout,total_fee,addtime,revevar1,revevar2,revevar3");
            strSql.Append(") values (");
            strSql.Append("@payorderid,@refund_fee,@refund_recv_accout,@total_fee,@addtime,@revevar1,@revevar2,@revevar3");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
               new SqlParameter("@payorderid", SqlDbType.VarChar,50) ,
               new SqlParameter("@refund_fee", SqlDbType.Float,8) ,
               new SqlParameter("@refund_recv_accout", SqlDbType.VarChar,256) ,
               new SqlParameter("@total_fee", SqlDbType.Float,8) ,
               new SqlParameter("@addtime", SqlDbType.DateTime) ,
               new SqlParameter("@revevar1", SqlDbType.VarChar,256) ,
               new SqlParameter("@revevar2", SqlDbType.VarChar,4000) ,
               new SqlParameter("@revevar3", SqlDbType.VarChar,4000)

            };

            parameters[0].Value = model.payorderid;
            parameters[1].Value = model.refund_fee;
            parameters[2].Value = model.refund_recv_accout;
            parameters[3].Value = model.total_fee;
            parameters[4].Value = model.addtime;
            parameters[5].Value = model.revevar1;
            parameters[6].Value = model.revevar2;
            parameters[7].Value = model.revevar3;
            return HJConvert.ToInt32(SQLHelper.ExecuteScalar(CommandType.Text, strSql.ToString(), parameters));
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int Update(WeChat_RefundLogInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update WeChat_RefundLog set ");

            strSql.Append(" payorderid = @payorderid , ");
            strSql.Append(" refund_fee = @refund_fee , ");
            strSql.Append(" refund_recv_accout = @refund_recv_accout , ");
            strSql.Append(" total_fee = @total_fee , ");
            strSql.Append(" addtime = @addtime , ");
            strSql.Append(" revevar1 = @revevar1 , ");
            strSql.Append(" revevar2 = @revevar2 , ");
            strSql.Append(" revevar3 = @revevar3  ");
            strSql.Append(" where Id=@Id ");

            SqlParameter[] parameters =
            {
                 new SqlParameter("@Id", SqlDbType.Int,4) ,
                 new SqlParameter("@payorderid", SqlDbType.VarChar,50) ,
                 new SqlParameter("@refund_fee", SqlDbType.Float,8) ,
                 new SqlParameter("@refund_recv_accout", SqlDbType.VarChar,256) ,
                 new SqlParameter("@total_fee", SqlDbType.Float,8) ,
                 new SqlParameter("@addtime", SqlDbType.DateTime) ,
                 new SqlParameter("@revevar1", SqlDbType.VarChar,256) ,
                 new SqlParameter("@revevar2", SqlDbType.VarChar,4000) ,
                 new SqlParameter("@revevar3", SqlDbType.VarChar,4000)

            };

            parameters[0].Value = model.Id;
            parameters[1].Value = model.payorderid;
            parameters[2].Value = model.refund_fee;
            parameters[3].Value = model.refund_recv_accout;
            parameters[4].Value = model.total_fee;
            parameters[5].Value = model.addtime;
            parameters[6].Value = model.revevar1;
            parameters[7].Value = model.revevar2;
            parameters[8].Value = model.revevar3;
            return SQLHelper.ExecuteNonQuery(CommandType.Text, strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获取记录所有字段
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <param>Id</param>
        /// <returns>WeChat_RefundLogInfo</returns>
        public WeChat_RefundLogInfo GetModel(int Id)
        {
            string sql = "select Id,payorderid,refund_fee,refund_recv_accout,total_fee,addtime,revevar1,revevar2,revevar3 from WeChat_RefundLog where  Id = @Id";
            SqlParameter parameter = new SqlParameter("@Id", SqlDbType.Int, 4);
            parameter.Value = Id;
            WeChat_RefundLogInfo model = null;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.Text, sql, parameter))
            {
                if (dr.Read())
                {
                    model = new WeChat_RefundLogInfo();
                    model.Id = HJConvert.ToInt32(dr["Id"]);
                    model.payorderid = HJConvert.ToString(dr["payorderid"]);
                    model.refund_fee = HJConvert.ToDecimal(dr["refund_fee"]);
                    model.refund_recv_accout = HJConvert.ToString(dr["refund_recv_accout"]);
                    model.total_fee = HJConvert.ToDecimal(dr["total_fee"]);
                    model.addtime = HJConvert.ToDateTime(dr["addtime"]);
                    model.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    model.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    model.revevar3 = HJConvert.ToString(dr["revevar3"]);
                }
            }
            return model;
        }

        /// <summary>
        /// 获得总记录数
        /// </summary>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int GetCount(string strWhere)
        {
            return (int)SQLHelper.ExecuteScalar(CommandType.StoredProcedure, "pagecount", new SqlParameter("@tblName", "WeChat_RefundLog"), new SqlParameter("@strWhere", strWhere));
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="pagesize">页尺寸</param>
        /// <param name="pageindex">页索引</param>
        /// <param name="strWhere">查询条件</param>
        /// <param name="orderName">排序字段</param>
        /// <param name="orderType">排序类型，1为降序，0为升序</param>
        /// <returns>列表</returns>
        ///此代码由杭景科技代码内部生成器自动生成
        public IList<WeChat_RefundLogInfo> GetList(int pagesize, int pageindex, string strWhere, string orderName, int orderType)
        {
            IList<WeChat_RefundLogInfo> infos = new List<WeChat_RefundLogInfo>();
            SqlParameter[] parameters =
                    {
                new SqlParameter("@tblName", SqlDbType.VarChar,255),
                new SqlParameter("@strGetFields", SqlDbType.VarChar,1000),
                new SqlParameter("@primary", SqlDbType.VarChar,255),
                new SqlParameter("@orderName", SqlDbType.VarChar,255),
                new SqlParameter("@PageSize", SqlDbType.Int),
                new SqlParameter("@PageIndex", SqlDbType.Int),
                new SqlParameter("@OrderType", SqlDbType.Bit),
                new SqlParameter("@strWhere", SqlDbType.VarChar,1500)
            };
            parameters[0].Value = "WeChat_RefundLog";
            parameters[1].Value = "Id,payorderid,refund_fee,refund_recv_accout,total_fee,addtime,revevar1,revevar2,revevar3";
            parameters[2].Value = "Id";
            parameters[3].Value = orderName;
            parameters[4].Value = pagesize;
            parameters[5].Value = pageindex;
            parameters[6].Value = orderType;
            parameters[7].Value = strWhere;
            using (SqlDataReader dr = SQLHelper.ExecuteReader(CommandType.StoredProcedure, "pageselectpri", parameters))
            {
                while (dr.Read())
                {
                    WeChat_RefundLogInfo model = new WeChat_RefundLogInfo();
                    model.Id = HJConvert.ToInt32(dr["Id"]);
                    model.payorderid = HJConvert.ToString(dr["payorderid"]);
                    model.refund_fee = HJConvert.ToDecimal(dr["refund_fee"]);
                    model.refund_recv_accout = HJConvert.ToString(dr["refund_recv_accout"]);
                    model.total_fee = HJConvert.ToDecimal(dr["total_fee"]);
                    model.addtime = HJConvert.ToDateTime(dr["addtime"]);
                    model.revevar1 = HJConvert.ToString(dr["revevar1"]);
                    model.revevar2 = HJConvert.ToString(dr["revevar2"]);
                    model.revevar3 = HJConvert.ToString(dr["revevar3"]);
                    infos.Add(model);
                }
            }
            return infos;
        }

        /// <summary>
        /// 删除一条记录
        /// </summary>
        /// <param name="Id"></param>
        /// 此代码由杭景科技代码内部生成器自动生成
        /// <returns></returns>
        public int DelWeChat_RefundLog(int Id)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from WeChat_RefundLog where Id=@Id");
            SqlParameter[] Para =
                {
                new SqlParameter("@Id",SqlDbType.Int)
            };
            Para[0].Value = Id;

            return SQLHelper.ExecuteNonQuery(CommandType.Text, str.ToString(), Para);
        }


        /// <summary>
        /// 批量删除记录
        /// </summary>
        /// <param name="IdList"></param>
        /// <returns></returns>
        /// 此代码由杭景科技代码内部生成器自动生成
        public int DelList(string IdList)
        {
            StringBuilder str = new StringBuilder();
            str.Append("delete from WeChat_RefundLog where Id in ({0})");

            return SQLHelper.ExecuteNonQuery(CommandType.Text, string.Format(str.ToString(), IdList), null);
        }
    }

}

